package cn.net.cfss.fgbp.provider.console.biz;

import cn.net.cfss.fgbp.api.console.constant.DeleteFlagEnum;
import cn.net.cfss.fgbp.api.console.dto.SysApplicationDto;
import cn.net.cfss.fgbp.api.console.vo.SysApplicationVo;
import cn.net.cfss.fgbp.base.common.biz.BaseBiz;
import cn.net.cfss.fgbp.provider.console.dao.SysApplicationDtoMapper;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import javax.transaction.Transactional;
import java.util.Date;
import java.util.List;

/**
 * @author oygq
 * @title: SysApplicationDtoBiz
 * @description: TODO
 * @date 2019/4/3 10:49
 */
@Service
public class SysApplicationDtoBiz extends BaseBiz<SysApplicationDtoMapper, SysApplicationDto> {

    public List<SysApplicationDto> queryByRoleId(Long roleCode) {
        return mapper.queryByRoleId(roleCode);
    }

    public List<SysApplicationDto> queryList(SysApplicationVo vo) {
        return mapper.queryList(vo);
    }

    @Transactional
    public void deleteBatch(List<Long> ids) {
        for (Long id : ids) {
            SysApplicationDto dto = new SysApplicationDto();
            dto.setId(id);
            dto.setUpdateTime(new Date());
            dto.setDeleteFlag(DeleteFlagEnum.DEL);
            updateSelectiveById(dto);
        }

    }

    public boolean check(String permission, Long id) {
        if (id != null) {
            SysApplicationDto dto = selectById(id);
            if (permission.equals(dto.getPermission())) {
                return true;
            }
        }
        if (mapper.check(permission) > 0) {
            return false;
        }
        return true;
    }

}
